# -*- coding: utf-8 -*-
import scrapy
from lxml import etree
from ..items import MobileNewsItem

class QqNewsSpider(scrapy.Spider):
    name = 'qq_news'
    allowed_domains = ['qq.com']
    start_urls = ['http://tech.qq.com/']

    def parse(self, response):
        s = etree.HTML(response.text)
        list = s.xpath('//div[@class="Q-tpList"]')
        for i in list:
            item = MobileNewsItem()
            item['title'] = i.xpath('./div[1]/div[1]/h3/a/text()')[0]
            item['url'] = i.xpath('./div[1]/div[1]/h3/a/@href')[0]
            item['img_url'] = i.xpath('./div[1]/a/img/@src')[0]
            item['source'] = '腾讯新闻'
            item['author'] = i.xpath('./div[1]/div[1]/div[2]/div[1]/div[1]/text()')[0]
            yield item